// component/dataBoard/teaDataBoard/teaDataBoard.js
const appg = getApp().globalData
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    uid: null,
    position_ID: null,
    userType: null,
    option1: [{
      text: '全部类型',
      value: 0
    }, ],
    option2: [{
        text: '统计全部',
        value: 'a'
      },
      {
        text: '统计今日',
        value: 'b'
      },
    ],
    value1: 0,
    value2: 'a',
    percent: 20,
    totalList:null
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 去详细
    to_dec(e) {
      console.log(e);
      const id = e.currentTarget.dataset.chatid
      const signAll = e.currentTarget.dataset.signall
      const qdCount = e.currentTarget.dataset.qdcount
      const wqdCount = e.currentTarget.dataset.wqdcount
      const chat_name = e.currentTarget.dataset.chatname
      wx.navigateTo({
        url: '/subHoliday/dataBoard/teaDec/teaDec?id='+id+'&t='+this.data.value2+'&signAll='+signAll+'&qdCount='+qdCount+'&wqdCount='+wqdCount+'&chat_name='+chat_name,
      })
    },
    // 获取数据
    async getData() {
      this.triggerEvent('Skeleton', {
        loading: true
      })
      const params = {
        uid: this.data.uid,
        userType: this.data.userType,
        type: this.data.value1,
        day: this.data.value2,
        position_ID: this.data.position_ID
      }
      const json = await getApp().$axios("/getDataKanBan", "POST", params)
      this.triggerEvent('Skeleton', {
        loading: false
      })
      if (json.status !== 200) {
        wx.showToast({
          title: '查询有误，请重试',
          icon: 'none'
        })
        return
      }
      if (json.data.totalSignIn==0) {
        this.setData({
          percent: 0,
          totalList: json.data
        })
        return
      }
      // 计算出勤率
      const percent = (json.data.signInCount / json.data.totalSignIn).toFixed(2)
      this.setData({
        percent: percent * 100,
        totalList: json.data
      })
    },
    //类型变化
    changeValue(e) {
      const value = e.detail
      this.setData({
        value2: value
      })
      this.getData()
    },
  },
  lifetimes: {
    attached: function () {
      this.setData({
        uid: appg.userInfo.id,
        userType: appg.userInfo.identity_ID,
        position_ID: appg.userInfo.position_ID
      })
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  // 组件在页面中的生命周期
  pageLifetimes: {
    show: function () {
      this.getData()
    },
    hide: function () {
      // 页面被隐藏
    },
    resize: function (size) {
      // 页面尺寸变化
    }
  }
})